package com.his.dictresource.service.impl;

import com.his.dictresource.dao.ResourceControlMapper;
import com.his.dictresource.entity.ResourceControl;
import com.his.dictresource.entity.ResourceControlInfo;
import com.his.dictresource.service.ResourceControlService;
import com.his.dictresource.vo.ResourceControlVo;
import com.his.login.entity.DictEmployee;
import com.xiao.common.util.BeanUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class ResourceControlServiceImpl implements ResourceControlService {

    @Resource
    private ResourceControlMapper resourceControlMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResourceControl selectResourceControl(ResourceControlVo resourceControlVo) throws Exception{
        ResourceControl resourceControl = new ResourceControl();
        if(resourceControlVo.getCurdate() != null){
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//           Date date = simpleDateFormat.parse(resourceControlVo.getCurdate());
            Date date = new Date();
            resourceControl.setCurdate(date);
            resourceControl.setDatetypeid(resourceControlVo.getDatetypeid());
            resourceControl.setResourceid(resourceControlVo.getResourceid());
            resourceControl.setResourcetypeid(resourceControlVo.getResourcetypeid());
        }
        return resourceControlMapper.rscontrol(resourceControl.getCurdate(),resourceControl.getDatetypeid(),resourceControl.getResourcetypeid(),resourceControl.getResourceid());
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<ResourceControlInfo> selectRosourceControlInfo(DictEmployee dictEmployee) throws Exception{

        ResourceControl resourceControl = new ResourceControl();

        resourceControl.setCurdate(new Date());
        resourceControl.setHospid(dictEmployee.getHOSPID());

        return resourceControlMapper.control_info(resourceControl);
    }

    @Override
    public List<ResourceControlInfo> selectRosourceControlRisdueamount(DictEmployee dictEmployee) throws Exception {
        ResourceControl resourceControl = new ResourceControl();

        resourceControl.setCurdate(new Date());
        resourceControl.setHospid(dictEmployee.getHOSPID());
        return resourceControlMapper.risdueamount(resourceControl);
    }

    @Override
    public List<ResourceControlInfo> selectDaytypeid(DictEmployee dictEmployee){

        ResourceControlInfo resourceControlInfo = new ResourceControlInfo();
        resourceControlInfo.setCurdate(new Date());
        resourceControlInfo.setHospid(dictEmployee.getHOSPID());
        return resourceControlMapper.control_datetypeid(resourceControlInfo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<ResourceControl> selectResourceControlDoctor(DictEmployee dictEmployee, ResourceControlVo resourceControlVo) throws Exception {
        ResourceControl resourceControl = BeanUtil.copyBean(resourceControlVo,ResourceControl.class);
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        Date date = simpleDateFormat.parse(resourceControlVo.getCurdate());

        resourceControl.setResourcetypeid("002000");
        resourceControl.setCurdate(new Date());
        resourceControl.setHospid(dictEmployee.getHOSPID());

        return resourceControlMapper.control_doctor(resourceControl);
    }
}
